<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Cedar-Lighting router for golang</title>
    <style>
        .header {
            display: flex;
            flex-flow: row nowrap;
            align-items: center;
            justify-content: space-around;
            height: 100px
        }

        .header > .logo {
            width: 80px;
            height: 80px
        }

        .list {
            list-style-type: none;
            font-size: 20px;
            font-weight: bold
        }

        .list > li {
            float: left;
            margin-right: 20px
        }

        .list > li > a {
            text-decoration: none;
            color: black
        }

        .container {
            display: flex;
            flex-flow: column nowrap;
            align-items: center
        }

        #index {
            width: 100%;
            display: flex;
            flex-flow: column nowrap;
            align-items: center
        }

        #usage {
            width: 80%
        }

        .bigCedar {
            font-size: 200pt;
            margin: 0;
            padding: 0;
            text-align: center;
            font-family: "Ubuntu"
        }

        .lineSpeak {
            font-size: 30pt;
            margin: 0;
            padding: 0;
            text-align: center;
            font-family: "Ubuntu"
        }

        .contributors {
            font-size: 20pt;
            margin: 0;
            padding: 0;
            text-align: center
        }

        .list2 {
            padding: 0;
            list-style-type: none
        }

        .list2 > li {
            float: left
        }

        .list2 > li > div {
            display: flex;
            flex-flow: column nowrap;
            align-items: center
        }

        .list2 > li > div > img {
            width: 80px;
            height: 80px;
            border-radius: 50%
        }

        .list2 > li > div > h4 {
            margin: 0
        }

        .px {
            color: #2c3e50;
            font-weight: bold;
        }

        .sp {
            color: rgb(123, 10, 176);
            font-weight: bolder;
        }

        .imp {
            color: rgb(248, 101, 12)
        }

        pre {
            white-space: pre-wrap;
            background-color: rgb(40, 44, 52);
            color: rgb(80, 173, 211);
            font-family: Consolas, "Andale Mono WT", "Andale Mono", "Lucida Console",
            "Lucida Sans Typewriter", "DejaVu Sans Mono", "Bitstream Vera Sans Mono",
            "Liberation Mono", "Nimbus Mono L", Monaco, "Courier New", Courier, monospace;
        }

        pre > code {
            color: rgb(80, 173, 211);
            font-family: Consolas, "Andale Mono WT", "Andale Mono", "Lucida Console",
            "Lucida Sans Typewriter", "DejaVu Sans Mono", "Bitstream Vera Sans Mono",
            "Liberation Mono", "Nimbus Mono L", Monaco, "Courier New", Courier, monospace;
        }
    </style>
    <script src="../../static/js/render.js"></script>
</head>
<body>
<header class="header">
    <img src="https://file.yaop.ink/81c4fc8e74672bc5ddd11b8db59b1fb279c6ef71.png" alt="" class="logo">
    <ul class="list" render-obj="data">
        <li><a>{{index}}</a></li>
        <li><a>{{usage}}</a></li>
        <li><a onclick="changeToEnglish()" id="changeLang">{{tips}}</a></li>
    </ul>
</header>
<div class="container">
    <div id="index" render-obj="data">
        <p class="bigCedar">Cedar</p>
        <p class="lineSpeak">{{lineSpeak}}</p>
        <br>
        <p class="contributors">{{contributors}}</p>
        <ul class="list2">
            <li>
                <div>
                    <img src="https://file.yaop.ink/d4810653bff615a839283c91039f4589.png" alt="">
                    <h4>Tong</h4>
                </div>
            </li>
        </ul>
    </div>
    <div id="usage" render-obj="data">
        <div>
            <h3>{{usages.one}}</h3>
            <hr>
            <p>{{usages.two}}</p>
            <pre>
                <code>
    type Son struct <
        key         string
        path        string
        deep        int
        child       map[string]*Son
        terminal    bool
        method      string
        handlerFunc http.HandlerFunc
        handler     http.Handler
    >
                </code>
            </pre>
        </div>
        <div>
            <h3>{{usages.three}}</h3>
            <hr>
            <p class="px">{{usages.four}}<span class="sp">prefix,http.HandlerFunc,http.Handler</span>)
            </p>
            <p class="px">{{usages.five}}<span class="sp">{{usages.six}}</span>{{usages.seven}}<span
                    class="sp">{{usages.eight}}</span>
            </p>
            <pre>
     // Change < >

    Normal
    r := cedar.NewRouter()
    r.Get("/",http.HandlerFunc(),nil)
    r.Post("/",http.HandlerFunc(),nil)
    r.Put("/",http.HandlerFunc(),nil)
    r.Delete("/",http.HandlerFunc(),nil)

    Group
    r := cedar.NewRouter()
    r.Group("/",func (group *cedar.Groups){
        group.Get("/",http.HandlerFunc(),nil)
        group.Group("/x",func(groups *cedar.Groups) {
            group.Get("/x",http.HandlerFunc(),nil)
        })
    })


    RestFul
    r := cedar.NewRestRouter(cedar.RestConfig{
		EntryPath: "blog",
		ApiName:   "api",
		Pattern:   ".",
    })
    r.Get("user", func(writer http.ResponseWriter, request *http.Request) {
            r.Template(writer, "/index")
    }, nil)
    //localhost/blog?api=user
            </pre>
        </div>
    </div>
</div>
</body>
<script>
    // 识别浏览器语言
    let nowTrans = -1;
    switch (navigator.language) {
        case "zh-CN":
            nowTrans = 1;
            break;
        case "en":
            nowTrans = 0;
            break;
        default:
            nowTrans = 0;

    }
    let changeLang = {
        ch: {
            index: "首页",
            usage: "使用",
            tips: "English",
            lineSpeak: "轻量级Golang路由器",
            contributors: "贡献者",
            usages: {
                one: "核心构建",
                two: "前缀树算法作为路由核心,能够实现普通的路由和群组路由,并且支持 HandlerFunc 和 Handler,轻松扩展和衔接",
                three: "使用方法(重要)",
                four: "普通路由的必要参数: cedar.NewRouter().Get(",
                five: "后两个参数我建议只填写",
                six: "一个",
                seven: ",同一个路径不能存在不同的请求方法,",
                eight: "会覆盖",
            }
        },
        en: {
            index: "Index",
            usage: "Usage",
            tips: "中文",
            lineSpeak: "A lightweight router for Golang",
            contributors: "Contributors",
            usages: {
                one: "Building core",
                two: "Prefix tree as core algorithm,it can support normal route as GET,POST... , and also support group route,easy to expand",
                three: "Usage(Important)",
                four: "The required parameters: cedar.NewRouter().Get(",
                five: "I suggest filling in only ",
                six: "one of the last two parameters",
                seven: ",and the same path can not have different request methods,",
                eight: "because it will cover the previous",
            }
        }
    };
    let headerTrans = new Render(".list");
    let lineSpeak = new Render("#index");
    let usage = new Render("#usage");
    changeToEnglish();

    // 切换显示语言
    function changeToEnglish() {
        if (nowTrans === 0) { // 显示英文
            headerTrans.obj({data: changeLang.en});
            lineSpeak.obj({data: changeLang.en});
            usage.obj({data: changeLang.en});
            nowTrans = 1;
        } else {  // 显示中文
            headerTrans.obj({data: changeLang.ch});
            lineSpeak.obj({data: changeLang.ch});
            usage.obj({data: changeLang.ch});
            nowTrans = 0;
        }
    }

    // 适应全屏幕
    let container = document.getElementsByClassName("container")[0];
    for (let i of container.childNodes) {
        if (i.constructor !== Text) {
            i.style.height = window.innerHeight + "px";
        }
    }
</script>
</html>